<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" media="screen" href="../../layui/css/layui.css">
</head>
<body>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
	<form class="form-horizontal" onsubmit="return false" id="form">
        <fieldset>
            <input type="hidden" id="id" name="id">
            <div class="form-group">
                <label class="col-md-2 control-label">设备组名</label>
                <div class="col-md-10">
                    <input class="form-control" placeholder="设备组名" type="text" name="groupname"
                           id="groupname"
                           data-bv-notempty="true"
                           data-bv-notempty-message="设备组名 不能为空">
                </div>
            </div>

            <div class="form-group">
                <label class="col-md-2 control-label">设备组备注</label>
                <div class="col-md-10">
                    <input class="form-control" placeholder="设备组备注" type="text" name="groupbackname"
                           id="groupbackname">
                </div>
            </div>
            <div class="form-actions">
                <div class="row" align="center">
                    <div class="col-md-12">
                        <button id="ReturnBt" class="btn btn-primary">返回</button>
                        <button class="btn btn-primary" type="submit" onclick="update()">
                            <i class="fa fa-save"></i> 保存
                        </button>
                    </div>
                </div>
            </div>

        </fieldset>
	</form>
</div>
	<script type="text/javascript" src="../../js/libs/jquery-2.1.1.min.js"></script>
	<script type="text/javascript" src="../../js/jq.js"></script>
	<script type="text/javascript" src="../../js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
	<script type="text/javascript" src="../../js/common.js"></script>
	<script type="text/javascript" src="../../js/my/roles/role.js"></script>
	<script type="text/javascript" src="../../layui/layui.js"></script>
	<script type="text/javascript" src="../../js/dict.js"></script>

	<script type="text/javascript">


	//initRoles();
	initData();
	function initData(){
		var id = getUrlParam("id");
		if(id !== ""){
			$.ajax({
				type : 'get',
				url : '/appusers/grouplist/getone/'+id,
				async : false,
				success : function(data) {
                    document.getElementById('id').value=data.id;
                    document.getElementById('groupname').value=data.groupname;
                    document.getElementById('groupbackname').value=data.groupbackname;
				}
			});
		}
	}
	
		$('#form').bootstrapValidator();

        var userid=getUrlParam("userid");
		function update() {
			var bootstrapValidator = $("#form").data('bootstrapValidator');
			bootstrapValidator.validate();
		    if(!bootstrapValidator.isValid()){
			   return;
		    }
		    var formdata = $("#form").serializeObject();
			$.ajax({
				type : 'put',
				url : '/appusers/grouplist/update',
				contentType: "application/json; charset=utf-8",  
				data : JSON.stringify(formdata),
				success : function() {
                    layui.use('layer', function () {
                        layer = layui.layer;
                        layer.msg("修改成功", {shift: -1, time: 1000}, function(){
                            location.href = "appGroups.html?userid=" + userid;
                        });
                    })
				}
			});
		}
    $("#ReturnBt").click(function(){
        var href = "appGroups.html?userid=" + userid;
        window.location=href;
    });
		
	</script>
</body>
</html>